<template>
  <div class="app-container">
    <div
      v-show="
        !modifyInfo.visible && !detailInfo.visible && !financeModifyInfo.visible
      "
    >
      <!-- 条件栏 -->
      <div class="filter-wrapper">
        <NewPageFilter
          ref="pageFilter"
          v-model:query="filterInfo.query.queryMap"
          :query-more-json="true"
          :filter-list="filterInfo.searchList"
          :filter-btn="filterInfo.searchBtn"
          :clear-type="clearType"
          :slip-select-request="slipSelectRequest"
        >
          <template v-slot:filter-useDeptNameRate>
            <slip-select
              v-model="filterInfo.query.queryParams.useDeptIdMult"
              value-key="value"
              style="width: 220px"
              placeholder="选择使用部门"
              :api="inOrOutDepotInfo.api"
              key-field="name"
              value-field="id"
              v-model:query="inOrOutDepotInfo.query"
              :clearable="true"
              :filterable="true"
              :multiple="true"
              @change="search"
            />
          </template>
          <template v-slot:filter-primitiveOriginalAmount>
            <div class="price-range">
              <el-input-number
                ref="codeInput"
                v-model="priceRange.left"
                placeholder="请输入原值小值"
                @keyup.enter="search"
                controls-position="right"
                :min="0"
                :max="priceRange.right ? priceRange.right : 99999999"
                :precision="
                  $store.state.permission.systemConfig.price_precision
                "
              />
              <span> ~ </span>
              <el-input-number
                ref="codeInput"
                v-model="priceRange.right"
                placeholder="请输入原值大值"
                @keyup.enter="search"
                controls-position="right"
                :precision="
                  $store.state.permission.systemConfig.price_precision
                "
                :min="priceRange.left"
                :max="99999999"
              />
            </div>
          </template>
        </NewPageFilter>
      </div>

      <div class="filter-wrapper">
        <NewPageFilter :filter-btn="filterInfo.btnList">
          <template v-slot:filter-printAsset>
            <el-button
              :disabled="!tableInfo.selections.length"
              @click="printAssetCode()"
              >打印资产条码</el-button
            >
          </template>
          <template v-slot:filter-uploadAsset>
            <el-upload
              :headers="uploadInfo.headers"
              :show-file-list="false"
              :on-error="uploadError"
              :on-success="importAsset"
              :before-upload="beforeProductUpload"
              :action="uploadInfo.action"
            >
              <el-button>模板导入</el-button>
            </el-upload>
          </template>
          <template v-slot:filter-uploadDict>
            <el-upload
              :headers="uploadInfo.headers"
              :show-file-list="false"
              :on-error="uploadError"
              :on-success="importAsset"
              :before-upload="beforeProductUpload"
              :action="uploadInfo.dictAction"
            >
              <el-button>字典模板导入</el-button>
            </el-upload>
          </template>
          <template v-slot:filter-ratify>
            <el-button :disabled="!canRatify" @click="ratify()">批准</el-button>
          </template>
          <template v-slot:filter-cancelAudit>
            <el-button :disabled="!canCancelAudit" @click="cancelAudit()"
              >销审</el-button
            >
          </template>
          <template v-slot:filter-submit>
            <el-button :disabled="!canSubmit" @click="submit()">提交</el-button>
          </template>
          <template v-slot:filter-update>
            <el-button :disabled="!canUpdate" @click="updateCard()"
              >批量修改</el-button
            >
          </template>
          <template v-slot:filter-confirmFinancialInformation>
            <el-button
              :disabled="!canConfirmFinancialInformation"
              @click="confirmFinancialInformation()"
              >财务信息确认</el-button
            >
          </template>
          <template v-slot:filter-upload>
            <el-button style="marginleft: 10px" @click="uploadImg"
              >上传图片</el-button
            >
          </template>
          <template v-slot:filter-print>
            <el-button :disabled="!canPrint" @click="print()">打印</el-button>
          </template>
          <template v-slot:filter-excel>
            <el-button :disabled="!canExcel" @click="exportExcel()"
              >导出excel</el-button
            >
          </template>
          <template v-slot:filter-importExcelWithFinancialAssetCode>
            <el-upload
              :headers="uploadInfo.headers"
              :show-file-list="false"
              :on-error="uploadError"
              :on-success="importAsset"
              :before-upload="beforeProductUpload"
              :action="uploadInfo.financialAction"
            >
              <el-button>财政资产模板导入</el-button>
            </el-upload>
          </template>
        </NewPageFilter>
        <div class="display-flex">
          <GroupSelect
            :options="groupSelectInfo.options"
            v-model:selections="groupSelectInfo.selections"
            @callback="groupSelect"
            @callbackVal="updateGroupSelections"
          ></GroupSelect>
          <el-button @click="preferenceInfo.visible = true">偏好设置</el-button>
        </div>
      </div>
      <!-- 表格 -->
      <table-container
        v-if="groupFlag"
        class="groupFlag-container"
        :is-group-search="true"
        v-model:data="groupSelectInfo.data"
        :field-list="tableInfo.fieldList"
        :check-box="false"
        :tab-index="false"
        :pager="false"
        :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
        :span-method="arraySpanMethod"
        :row-class-name="tableRowClassName"
        @exChange="exChange"
        @sortChange="sortChange"
        @handleEvent="handleEvent"
      >
        <template v-slot:col-assetName="scope">
          <span>{{ scope.row.assetName || '-' }}</span>
        </template>
      </table-container>
      <!-- 表格 -->
      <table-container
        v-else
        :refresh="tableInfo.refresh"
        :init-curpage="tableInfo.initCurpage"
        v-model:data="tableInfo.data"
        :api="tableInfo.api"
        :tab-index="false"
        :check-box="true"
        :query="filterInfo.query"
        :field-list="tableInfo.fieldList"
        :handle="tableInfo.handle"
        :row-class-name="tableRowOtherClassName"
        :summary="true"
        :summary-field-list="tableInfo.summaryFieldList"
        :allSummary="true"
        :allSummaryData="allSummaryData"
        @pageInfo="pageInfo"
        @handleEvent="handleEvent"
      >
        <template v-slot:col-assetName="scope">
          <span class="slip-edit" @click="showProductDetail(scope.row)">
            {{ scope.row.assetName || '-' }}
          </span>
        </template>
      </table-container>
    </div>
    <!-- 新增或修改 -->
    <assetCard-modify
      v-if="modifyInfo.visible"
      :id="modifyInfo.id"
      v-model:visible="modifyInfo.visible"
      :title="modifyInfo.title"
      :canModifyModule="modifyInfo.canModifyModule"
      :type="modifyInfo.type"
      :current-accounting-interval="modifyInfo.currentAccountingInterval"
      :buildCardData="modifyInfo.buildCardData"
      @returnModify="returnModify"
    />

    <!-- 详情页 -->
    <assetCard-detail
      v-if="detailInfo.visible"
      :id="detailInfo.id"
      v-model:visible="detailInfo.visible"
      :title="detailInfo.title"
      @returnBack="getList"
    />

    <set-preference
      v-if="preferenceInfo.visible"
      v-model:visible="preferenceInfo.visible"
      :search-list="filterInfo.searchList"
      :field-list="tableInfo.fieldList"
      :customize-user-v-o="filterInfo.query.customizeUserVO"
      @callback="setPreferenceCallback"
    />
    <advanced-search
      v-if="advancedSearchInfo.visible"
      v-model:visible="advancedSearchInfo.visible"
      :field-list="tableInfo.fieldList"
      v-model:form-data="advancedSearchInfo.data"
      @callback="advancedSearchCallback"
    />
    <chose-printer
      :visible="printerInfo.visible"
      @callBack="handlePrinterCallBack"
    />
    <page-dialog
      v-show="dialogInfo.visible"
      :title="dialogInfo.title"
      v-model:visible="dialogInfo.visible"
      :width="dialogInfo.width"
      :bt-loading="dialogInfo.btLoading"
      :bt-list="dialogInfo.btList"
    >
      <div class="asset-msg">
        <div class="asset-msg-label">
          <i class="el-icon-warning"></i>{{ dialogInfo.msg }}：
        </div>
        <el-radio-group v-model="dialogInfo.flag">
          <el-radio label="page">当前页数据</el-radio>
          <el-radio label="all">全部页数据</el-radio>
          <el-radio label="select">仅选择数据</el-radio>
        </el-radio-group>
      </div>
    </page-dialog>
    <page-dialog
      v-show="downloadDialog.visible"
      :title="downloadDialog.title"
      v-model:visible="downloadDialog.visible"
      :width="downloadDialog.width"
      :bt-loading="downloadDialog.btLoading"
      :bt-list="downloadDialog.btList"
    >
      <div class="asset-msg">
        <div class="asset-msg-label">
          <i class="el-icon-warning"></i>{{ downloadDialog.msg }}：
        </div>
        <el-radio-group v-model="downloadDialog.flag">
          <el-radio label="card">资产模板</el-radio>
          <el-radio label="dict">资产字典模板</el-radio>
          <el-radio label="financial_asset">财政资产模板</el-radio>
        </el-radio-group>
      </div>
    </page-dialog>

    <!-- 财务信息登记 -->
    <RegisterFinancialInformation
      v-if="financeModifyInfo.visible"
      :id="financeModifyInfo.id"
      v-model:visible="financeModifyInfo.visible"
      :title="financeModifyInfo.title"
      :currentAccountingInterval="financeModifyInfo.currentAccountingInterval"
      :type="financeModifyInfo.type"
      @returnModify="returnFinanceModifyInfo"
    />
    <DialogUpload
      v-if="dialogUploadInfo.visible"
      v-model:show-dialog="dialogUploadInfo.visible"
      :vaildate-api="dialogUploadInfo.vaildateApi"
      :api="dialogUploadInfo.api"
      @callback="getList"
    >
    </DialogUpload>
    <BuildCard
      v-if="buildCardInfo.visible"
      v-model:visible="buildCardInfo.visible"
      @callback="callbackBuildCard"
    />
    <assetCardSplit
      v-if="assetCardSplitDialog.visible"
      @callback="getList"
      v-model:showDialog="assetCardSplitDialog.visible"
      :row="assetCardSplitDialog.row"
    />
    <assetCardSUpdate
      v-if="assetCardUpdateDialog.visible"
      @callback="getList"
      v-model:showDialog="assetCardUpdateDialog.visible"
      :assetIds="assetCardUpdateDialog.assetIds"
    />
  </div>
</template>

<script setup name="assetCard">
import axios from 'axios'
import AssetCardModify from '@/views/asset/assetManage/assetCard/modify'
import AssetCardDetail from '@/views/asset/assetManage/assetCard/details'
import RegisterFinancialInformation from '@/views/asset/assetManage/assetCard/financeModify'
import assetCardSplit from './component/assetCardSplit.vue'
import assetCardSUpdate from './component/assetCardSUpdate.vue'
import BuildCard from '@/views/asset/assetManage/assetCard/buildCard'
import {
  specialDeleteAssetCard,
  getAssetCardCustomizePage,
  getAssetCardCustomizeGroups,
  getAssetCardAll,
  revokeAssetCardOrder,
  submitAssetCardOrder,
  ratifyAssetCardOrder,
  cancelAuditAssetCardOrder,
  removeAssetCardOrder,
  rejectAssetCardOrder,
  refuseAssetCardOrder,
  assetCodePrint,
  exportAssetCard,
  getAssetCardPrint,
  financeCancel,
  financeRatify,
  financeReject,
  financeRevoke,
  financeSubmit,
  assetCardFile,
  assetCardVaildateFile,
  getDepotAll,
  downloadFileAssetCard,
  getCurrentFiscalPeriod,
  getDepotsSelectAllAndMaintenanceGroup,
  getDeptsSelectAllAndMaintenanceGroup,
  getDeptAll,
  addByBatchBuildCard,
  getAssetCardCustomizeListSumAmount,
} from '@/api/core.js'
import { getBusinessKeyById } from '@/api/flowable'
import { getCustomizeSetting, updateUserCustomize } from '@/api/customize'

import { ElLoading } from 'element-plus'
import { getAccountingInterval } from '@/api/asset.js'
import { exportTemplateExcel } from '@/api/pub.js'
import { fatchTemplateByCode } from '@/api/base.js'
const { proxy } = getCurrentInstance()
const dialogUploadInfo = ref({
  visible: false,
  api: assetCardFile,
  vaildateApi: assetCardVaildateFile,
})
const uploadInfo = ref({
  action:
    axios.defaults.baseURL + '/core/asset/assetManage/assetCard/import/excel',
  dictAction:
    axios.defaults.baseURL +
    '/core/asset/assetManage/assetCard/import/dictExcel',
  beginAction:
    axios.defaults.baseURL +
    '/core/asset/assetManage/assetCard/importBegin/excel',
  financialAction:
    axios.defaults.baseURL +
    '/core/asset/assetManage/assetCard/import/importExcelWithFinancialAssetCode',
  headers: {
    Authorization: proxy.$store.state.user.token,
  },
  loading: {},
})
// 过滤相关配置
const groupSelectInfo = ref({
  options: [],
  selections: [],
  data: [],
})
const assetCardSplitDialog = ref({
  visible: false,
  row: {},
})
const assetCardUpdateDialog = ref({
  visible: false,
  assetIds: [],
})
const priceRange = ref({
  left: null,
  right: null,
})
const filterInfo = ref({
  sortArr: [],
  copyQueryMap: {},
  searchList: [],
  searchBtn: [
    { type: 'button', label: '搜索', event: search },
    { type: 'button', label: '高级查询', event: advancedSearchShow },
    { type: 'button', label: '重置', event: clearSearch },
  ],
  query: {
    sortString: '',
    customizeUserVO: {},
    queryMap: {
      assetSourceAuth: {
        asTbName: 'core_asset,core_asset',
        columnName: 'use_dept_id,depot_id',
        queryType: 'IN',
        queryCategory: 'AND',
        value: 'assetSourceAuth',
      },
      id: {
        queryType: 'IN',
        queryCategory: 'AND',
        value: '',
      },
      primitiveOriginalAmount: {
        queryType: 'OPEN_INTERVAL',
        queryCategory: 'AND',
        value: '',
      },
    },
    queryParams: {
      isAssetAchievesExcel: 'true',
    },
  },
  btnList: [
    {
      type: 'button',
      label: '新增',
      event: create,
      show: proxy.$permission('assetCard:add'),
    },
    {
      type: 'slot',
      value: 'submit',
      show: proxy.$permission('assetCard:submit'),
    },
    {
      type: 'slot',
      value: 'ratify',
      show:
        proxy.$permission('assetCard:approve') &&
        proxy.$store.state.permission.systemConfig
          .assets_register_approval_type == 1,
    },
    {
      type: 'slot',
      value: 'cancelAudit',
      show: proxy.$permission('assetCard:cancelAudit'),
    },
    // {
    //   type: 'slot',
    //   value: 'confirmFinancialInformation',
    //   label: '财务信息确认',
    //   show: proxy.$permission('assetCard:confirmFinancialInformation'),
    // },
    {
      type: 'button',
      label: '批量建卡',
      event: buildCard,
      show: proxy.$permission('assetCard:buildCard'),
    },
    {
      type: 'slot',
      value: 'update',
      show: proxy.$permission('assetCard:batchUpdateAttribute'),
    },

    {
      type: 'slot',
      value: 'printAsset',
      show: proxy.$permission('assetCard:printAsset'),
    },
    {
      type: 'slot',
      value: 'uploadAsset',
      show: proxy.$permission('assetCard:import'),
    },
    {
      type: 'slot',
      value: 'uploadDict',
      show: proxy.$permission('assetCard:import'),
    },
    {
      type: 'button',
      label: '下载导入模板',
      event: downloadTemplateOpen,
      show: proxy.$permission('assetCard:downloadTemplate'),
    },
    {
      type: 'slot',
      value: 'excel',
      show: proxy.$permission('assetCard:excel'),
    },
    {
      type: 'slot',
      value: 'print',
      show: proxy.$permission('assetCard:printListCard'),
    },
    {
      type: 'slot',
      value: 'upload',
      show: proxy.$permission('assetCard:upload'),
    },
    {
      type: 'button',
      label: '下载图片',
      event: downloadFile,
      show: proxy.$permission('assetCard:downloadFile'),
    },
    {
      type: 'slot',
      value: 'importExcelWithFinancialAssetCode',
      show: proxy.$permission('assetCard:importExcelWithFinancialAssetCode'),
    },
  ],
})
const clearType = ref(true)
const slipSelectRequest = ref(true)
const tableInfo = ref({
  refresh: 1,
  initCurpage: 1,
  data: [],
  api: undefined,
  selections: [],
  fieldList: [],
  summaryFieldList: [
    { value: 'originalAmount', formatter: proxy.$fn.qtyFormatter },
    { value: 'primitiveOriginalAmount', formatter: proxy.$fn.qtyFormatter },
    {
      value: 'netAmount',
      formatter: proxy.$fn.qtyFormatter,
    },
    { value: 'sumDeprAmount', formatter: proxy.$fn.qtyFormatter },
    { value: 'qty', formatter: proxy.$fn.qtyFormatter },
    { value: 'deprPreparation', formatter: proxy.$fn.qtyFormatter },
    { value: 'installCost', formatter: proxy.$fn.qtyFormatter },
    { value: 'transportCost', formatter: proxy.$fn.qtyFormatter },
    { value: 'taxCost', formatter: proxy.$fn.qtyFormatter },
  ],
  handle: {
    fixed: 'right',
    label: '操作',
    width: '160',
    btList: [
      {
        label: '修改',
        event: update,
        show: proxy.$permission('assetCard:update'),
        ifRender: function (row) {
          return [1, 6].includes(row.status) && row.assetStatus !== 2
        },
      },
      {
        label: '提交',
        event: submit,
        show: proxy.$permission('assetCard:submit'),
        ifRender: function (row) {
          return [1, 6].includes(row.status) && row.assetStatus !== 2
        },
      },
      {
        label: '删除',
        event: remove,
        popconfirmText: '删除后将改变数据,是否继续？',
        show: proxy.$permission('assetCard:delete'),
        ifRender: function (row) {
          return [1, 6].includes(row.status) && row.assetStatus !== 2
        },
      },
      {
        label: '批准',
        event: ratify,
        show: proxy.$permission('assetCard:approve'),
        ifRender: function (row) {
          return (
            row.status === 2 &&
            (row.assetStatus === 1 || row.assetStatus === 3) &&
            proxy.$store.state.permission.systemConfig
              .assets_register_approval_type == 1
          )
        },
      },
      {
        label: '销审',
        event: cancelAudit,
        show: proxy.$permission('assetCard:cancelAudit'),
        ifRender: function (row) {
          return (
            // 按钮批准 或者 流程批准  已登记且 是审批
            row.status === 3 &&
            row.assetStatus !== 2 &&
            Number(
              proxy.$store.state.permission.systemConfig
                .assets_register_approval_type
            ) !== 0
          )
        },
      },
      {
        label: '撤回',
        event: revoke,
        show: proxy.$permission('assetCard:revoke'),
        ifRender: function (row) {
          return (
            (row.status === 2 ||
              (row.status === 3 &&
                Number(
                  proxy.$store.state.permission.systemConfig
                    .assets_register_approval_type
                ) === 0)) &&
            (row.assetStatus === 1 || row.assetStatus === 3)
          )
        },
      },
      {
        label: '驳回',
        event: reject,
        show: proxy.$permission('assetCard:reject'),
        ifRender: function (row) {
          return (
            row.status === 2 &&
            (row.assetStatus === 1 || row.assetStatus === 3) &&
            proxy.$store.state.permission.systemConfig
              .assets_register_approval_type == 1
          )
        },
      },
      {
        label: '拒绝',
        event: refuse,
        show: proxy.$permission('assetCard:refuse'),
        ifRender: function (row) {
          return (
            row.status === 2 &&
            (row.assetStatus === 1 || row.assetStatus === 3) &&
            proxy.$store.state.permission.systemConfig
              .assets_register_approval_type == 1
          )
        },
      },
      {
        label: '资产拆分',
        event: _assetCardSplit,
        show: proxy.$permission('assetCard:splitCard'),
        ifRender: function (row) {
          return (
            row.status === 3 && (row.assetStatus === 1 || row.assetStatus === 3)
          )
        },
      },
      {
        label: '信息补录/修改',
        event: replenishMaintenance,
        show: proxy.$permission('assetCard:replenishMaintenance'),
        ifRender: function (row) {
          return row.status === 3 && row.assetStatus !== 2
        },
      },
      {
        label: '特殊删除',
        event: specialDelete,
        popconfirmText: '特殊删除后将改变数据,是否继续？',
        show: proxy.$permission('assetCard:specialDelete'),
        ifRender: function (row) {
          return row.status === 3 && row.isCurrentMonth && row.assetStatus !== 2
        },
      },
      {
        label: '复制并新增',
        event: copyCreate,
        show: proxy.$permission('assetCard:copyCreate'),
        ifRender: function (row) {
          return (
            [1, 3].includes(row.status) &&
            [1, 2].includes(row.useStatus) &&
            row.assetStatus !== 2
          )
        },
      },
      // {
      //   label: '财务信息登记',
      //   event: registerFinancialInformation,
      //   show: proxy.$permission('assetCard:registerFinancialInformation'),
      //   ifRender: function (row) {
      //     return (
      //       row.status === 3 && (row.assetStatus === 1 || row.assetStatus === 3)
      //     )
      //   },
      // },
      // {
      //   label: '财务信息修改',
      //   event: updateFinancialInformation,
      //   show: proxy.$permission('assetCard:updateFinancialInformation'),
      //   ifRender: function (row) {
      //     return (
      //       row.status === 4 && (row.assetStatus === 1 || row.assetStatus === 3)
      //     )
      //   },
      // },
      // {
      //   label: '财务信息提交',
      //   event: submitFinancialInformation,
      //   show: proxy.$permission('assetCard:submitFinancialInformation'),
      //   ifRender: function (row) {
      //     return (
      //       row.status === 4 && (row.assetStatus === 1 || row.assetStatus === 3)
      //     )
      //   },
      // },
      // {
      //   label: '取消财务登记',
      //   event: cancelFinancialInformation,
      //   show: proxy.$permission('assetCard:cancelFinancialInformation'),
      //   ifRender: function (row) {
      //     return (
      //       row.status === 4 && (row.assetStatus === 1 || row.assetStatus === 3)
      //     )
      //   },
      // },
      // {
      //   label: '财务信息确认',
      //   event: confirmFinancialInformation,
      //   show: proxy.$permission('assetCard:confirmFinancialInformation'),
      //   ifRender: function (row) {
      //     return (
      //       row.status === 5 && (row.assetStatus === 1 || row.assetStatus === 3)
      //     )
      //   },
      // },
      // {
      //   label: '财务信息驳回',
      //   event: rejectFinancialInformation,
      //   show: proxy.$permission('assetCard:rejectFinancialInformation'),
      //   ifRender: function (row) {
      //     return (
      //       row.status === 5 && (row.assetStatus === 1 || row.assetStatus === 3)
      //     )
      //   },
      // },
      // {
      //   label: '财务信息撤回',
      //   event: revokeFinancialInformation,
      //   show: proxy.$permission('assetCard:revokeFinancialInformation'),
      //   ifRender: function (row) {
      //     return (
      //       row.status === 5 && (row.assetStatus === 1 || row.assetStatus === 3)
      //     )
      //   },
      // },
      // {
      //   label: '财务信息调整',
      //   event: financeAdjust,
      //   show: proxy.$permission('assetCard:financeAdjust'),
      //   ifRender: function (row) {
      //     return (
      //       row.status === 6 &&
      //       (row.assetStatus === 1 || row.assetStatus === 3) &&
      //       row.isCurrentMonth
      //     )
      //   },
      // },
    ],
  },
})
const allSummaryData = ref({
  data: [],
  fieldList: [
    {
      label: '总原值',
      value: 'primitiveOriginalAmount',
      type: 'column',
      formatter: proxy.$fn.TripartiteMethod,
    },
  ],
})
const printerInfo = ref({
  visible: false,
  data: {},
})
//明细相关
const detailInfo = ref({
  visible: false,
  title: '资产档案明细',
  id: '',
})
//新增或更新相关
const modifyInfo = ref({
  visible: false,
  title: '',
  id: '',
  currentAccountingInterval: '',
  type: '',
  canModifyModule: '',
})

//财务信息修改
const financeModifyInfo = ref({
  visible: false,
  title: '财务信息登记',
  id: '',
  currentAccountingInterval: '',
  type: '',
  buildCardData: [],
})
const preferenceInfo = ref({
  visible: false,
})
const groupFlag = ref(false)
const advancedSearchInfo = ref({
  visible: false,
  data: {},
})
const downloadDialog = ref({
  visible: false,
  title: '提示',
  btLoading: false,
  type: '',
  msg: '请选择要下载的模板',
  width: '400px',
  flag: 'page',
  btList: [
    { label: '关闭', event: handleCloseDown, show: true },
    {
      label: '下载',
      type: 'primary',
      event: downloadTemplate,
      show: true,
    },
  ],
})
const dialogInfo = ref({
  visible: false,
  title: '提示',
  btLoading: false,
  type: '',
  msg: '',
  width: '400px',
  flag: 'page',
  btList: [
    { label: '关闭', event: handleClose, show: true },
    {
      label: '打印',
      type: 'primary',
      event: checkConfirm,
      show: true,
    },
  ],
})
const page = ref({
  page: true,
  curPage: 1, // 当前页
  pageSize: 20, // 每页条数
})
const buildCardInfo = ref({
  visible: false,
})
const canSubmit = computed(() => {
  return (
    tableInfo.value.selections.length &&
    !tableInfo.value.selections.filter((item) => ![1, 6].includes(item.status))
      .length
  )
})
const canRevoke = computed(() => {
  return (
    tableInfo.value.selections.length &&
    !tableInfo.value.selections.filter((item) => item.status !== 2).length
  )
})
const canRatify = computed(() => {
  return (
    tableInfo.value.selections.length &&
    !tableInfo.value.selections.filter(
      (item) =>
        item.status !== 2 && (item.assetStatus !== 1 || item.assetStatus !== 3)
    ).length
  )
})
const canCancelAudit = computed(() => {
  return (
    tableInfo.value.selections.length &&
    Number(
      proxy.$store.state.permission.systemConfig.assets_register_approval_type
    ) !== 0 &&
    !tableInfo.value.selections.filter((item) => item.status !== 3).length
  )
})
const canUpdate = computed(() => {
  return (
    tableInfo.value.selections.length &&
    tableInfo.value.selections.filter((item) => item.status == 1).length
  )
})
const canConfirmFinancialInformation = computed(() => {
  return (
    tableInfo.value.selections.length &&
    !tableInfo.value.selections.filter((item) => item.status !== 5).length
  )
})
const canPrint = computed(() => {
  return !groupFlag.value
})
const canExcel = computed(() => {
  return !groupFlag.value
})

watch(
  () => proxy.$router.currentRoute.value.name,
  (to, from) => {
    if (!from) return
    if (
      from.includes('myPendingDetail') ||
      from.includes('myFinishedDetail') ||
      from.includes('myApplyDetail')
    ) {
      getList()
    }
  },
  {
    deep: true,
  }
)

let obj = {
  supplierName: {
    label: '供应商',
    value: 'supplierName',
    componentType: 'input',
    show: false,
    hidden: true,
  },
  assetName: {
    label: '资产名称',
    value: 'assetName',
    componentType: 'input',
    show: false,
    type: 'slot',
    hidden: true,
  },
  statusValue: {
    label: '状态',
    value: 'statusValue',
    asValue: 'status',
    componentType: 'select-model',
    code: 'asset_register_status',
    show: false,
    hidden: true,
  },
  assetTypeValue: {
    label: '资产类型',
    value: 'assetTypeValue',
    asValue: 'assetType',
    componentType: 'select-model',
    code: 'asset_type',
    show: false,
    hidden: true,
  },
  // accrualMarkValue: {
  //   label: '计提标志',
  //   value: 'accrualMarkValue',
  //   asValue: 'accrualMark',
  //   componentType: 'select-model',
  //   code: 'accrual_mark',
  //   show: false,
  //   hidden: true,
  // },
  increaseTypeValue: {
    label: '增加方式',
    value: 'increaseTypeValue',
    asValue: 'increaseType',
    componentType: 'select-model',
    code: 'increase_type',
    show: false,
    hidden: true,
  },
  deprConventionValue: {
    label: '折旧惯例',
    value: 'deprConventionValue',
    asValue: 'deprConvention',
    componentType: 'select-model',
    code: 'depr_convention',
    show: false,
    hidden: true,
  },
  deprMethodTypeValue: {
    label: '折旧方法',
    value: 'deprMethodTypeValue',
    asValue: 'deprMethodType',
    componentType: 'select-model',
    code: 'depr_method_type',
    show: false,
    hidden: true,
  },
  isLockedValue: {
    label: '是否锁定',
    value: 'isLockedValue',
    asValue: 'isLocked',
    componentType: 'select-model',
    code: 'is_locked',
    show: false,
    hidden: true,
  },
  assetStatusValue: {
    label: '资产状态',
    value: 'assetStatusValue',
    asValue: 'assetStatus',
    componentType: 'select-model',
    code: 'asset_status',
    show: false,
    hidden: true,
  },
  depotName: {
    label: '出库仓库',
    value: 'depotName',
    asValue: 'depotId',
    componentType: 'slip-select',
    query: {
      depotAuth: 'id',
      status: 1,
      useTypeId: '2',
    },
    api: getDepotsSelectAllAndMaintenanceGroup,
    show: false,
    hidden: true,
  },
  useDeptNameRate: {
    label: '使用部门-比例',
    value: 'useDeptNameRate',
    componentType: 'input',
    slot: true,
    type: 'column',
    show: false,
    hidden: true,
  },
  primitiveOriginalAmount: {
    label: '原值',
    value: 'primitiveOriginalAmount',
    type: 'column',
    componentType: 'number',
    slot: true,
    formatter: proxy.$fn.TripartiteMethodAsset,
    show: false,
    hidden: true,
  },
  purchTypeValue: {
    label: '采购类型',
    value: 'purchTypeValue',
    asValue: 'purchType',
    componentType: 'select-model',
    code: 'asset_purch_type',
    show: false,
    hidden: true,
  },
}
tableInfo.value.fieldList = Object.values({
  ...proxy.$fn.deepClone(proxy.$fieldfList.FieldList),
  ...proxy.$fn.deepClone(obj),
})
filterInfo.value.searchList = Object.values({
  ...proxy.$fn.deepClone(proxy.$fieldfList.FieldList),
  ...proxy.$fn.deepClone(obj),
})
getCustomize()

const inOrOutDepotInfo = reactive({
  api: getDeptAll,
  query: {
    deptAuth: 'id',
    status: 1,
  },
})
function getSummary() {
  getAssetCardCustomizeListSumAmount(filterInfo.value.query).then((res) => {
    if (res && res.success) {
      if (res.data) {
        allSummaryData.value.data = [
          { primitiveOriginalAmount: res.data.primitiveOriginalAmount },
        ]
      } else {
        allSummaryData.value.data = []
      }
    }
  })
}
function buildCard() {
  buildCardInfo.value.visible = true
}
function updateCard() {
  assetCardUpdateDialog.value.visible = true
  assetCardUpdateDialog.value.assetIds = tableInfo.value.selections.map(
    (item) => item.id
  )
  console.log(assetCardUpdateDialog.value.assetIds)
}
function callbackBuildCard(data) {
  ///批量建卡返回
  if (data && data.length) {
    let orderIds = data.map((element) => {
      return element.id
    })
    getCurrentFiscalPeriod(2).then((resp) => {
      if (resp && resp.success && resp.data) {
        buildCardInfo.value.visible = false
        modifyInfo.value.currentAccountingInterval = resp.data.startDate
      } else {
        proxy.$message({
          type: 'error',
          duration: 3500,
          message: '未开启会计期间，请先开启会计期间!',
          showClose: true,
        })
        return
      }
      addByBatchBuildCard(orderIds).then((resp) => {
        if (resp && resp.success) {
          buildCardInfo.value.visible = false
          search()
        }
      })
      /* proxy.$nextTick(() => {
        modifyInfo.value.type = 'buildCard'
        modifyInfo.value.visible = true
        modifyInfo.value.title = '新增资产卡片'
        modifyInfo.value.id = null
        modifyInfo.value.buildCardData = data
      }) */
    })
  }
}

function downloadFile() {
  downloadFileAssetCard(filterInfo.value.query).then((res) => {
    if (res) {
      proxy.$fn.parseExcel(res)
    }
  })
}
function downloadFinancialAssetCodeTemplate() {
  downloadDialog.value.visible = true
}
function pageInfo(obj) {
  page.value = obj
}
function uploadImg() {
  dialogUploadInfo.value.visible = true
}
function handleClose() {
  dialogInfo.value.visible = false
}
function handleCloseDown() {
  downloadDialog.value.visible = false
}
function showProductDetail(row) {
  getBusinessKeyById({
    businessKey: row.assetCode,
    businessType: 'assetCard',
  }).then((res) => {
    if (res.success) {
      sessionStorage.setItem('storeRowId', row.id)
      if (res.data?.processInstanceId) {
        proxy.$fn.setFlowData(res.data, '', proxy.$route)
      } else {
        detailInfo.value.visible = true
        detailInfo.value.title = '资产详情'
        detailInfo.value.id = row.id
      }
    }
  })
}
function tableRowOtherClassName({ row }) {
  let rowId = sessionStorage.getItem('storeRowId')
  if (rowId && row.id === Number(rowId)) {
    return 'check-row'
  }
  return ''
}
function returnModify() {
  if (modifyInfo.value.id) {
    getList()
  } else {
    search()
  }
}
function beforeProductUpload(file) {
  //发生请求时打开加载动画
  uploadInfo.value.loading = ElLoading.service({
    fullscreen: true,
    background: 'rgba(255,255,255,.4)',
  })
  let fileType = ['xlsx']
  let fileSize = proxy.$store.state.permission.systemConfig.max_file_size
  let isFileType = fileType.some(
    (type) => file.name.split('.')[file.name.split('.').length - 1] === type
  )
  const isLt = file.size / 1024 / 1024 < fileSize
  if (!isFileType) {
    proxy.$message.error({
      message: `文件格式不正确, 请上传 ${fileType.join(' / ')} 格式文件!`,
      showClose: true,
      duration: 3500,
    })
    uploadInfo.value.loading.close()
    return false
  }
  if (!isLt) {
    proxy.$message.error({
      message: `上传文件大小不能超过 ${fileSize} MB!`,
      showClose: true,
      duration: 3500,
    })
    uploadInfo.value.loading.close()
    return false
  }
  return isFileType && isLt
}
function importAsset(resp) {
  uploadInfo.value.loading.close()
  if (resp && resp.success) {
    proxy.$message.success({
      duration: 3500,
      showClose: true,
      message: resp.msg,
    })
    getList()
  } else {
    proxy.$message.error({
      message: resp.msg,
      duration: 0,
      showClose: true,
    })
  }
}
function uploadError(err) {
  if (err) {
    proxy.$message.error({
      message: '系统错误',
      duration: 3000,
      showClose: true,
    })
  }
  uploadInfo.value.loading.close()
}
function printAssetCode(row) {
  let data = []
  if (row && row.id) {
    data.push(row.id)
  } else {
    data = tableInfo.value.selections.map((item) => item.id)
  }
  if (data.length) {
    assetCodePrint(data).then((res) => {
      if (res && res.success) {
        printerInfo.value.visible = true
        printerInfo.value.data = res.data
      }
    })
  } else {
    proxy.$message({
      message: '选择需要打印的二维码',
      type: 'warning',
      duration: 3500,
      showClose: true,
    })
  }
}

function submit(row = undefined) {
  let ids = []
  if (row) {
    ids.push(row.id)
  } else {
    ids = tableInfo.value.selections.map((item) => item.id)
  }
  let data = {
    flowTaskCommentDto: { approvalType: 'submit' },
    processDefinitionKey: 'assetCard',
    orderIds: ids,
  }
  submitAssetCardOrder(data).then((resp) => {
    if (resp && resp.success) {
      getList()
    }
  })
}
function revoke(row = undefined) {
  let ids = []

  if (row) {
    ids.push(row.id)
  } else {
    ids = tableInfo.value.selections.map((item) => item.id)
  }
  revokeAssetCardOrder(ids).then((resp) => {
    if (resp && resp.success) {
      getList()
    }
  })
}
function ratify(row = undefined) {
  let ids = []
  if (row) {
    ids.push(row.id)
  } else {
    ids = tableInfo.value.selections.map((item) => item.id)
  }
  ratifyAssetCardOrder(ids).then((resp) => {
    if (resp && resp.success) {
      getList()
    }
  })
}
function cancelAudit(row = undefined) {
  let ids = []

  if (row) {
    ids.push(row.id)
  } else {
    ids = tableInfo.value.selections.map((item) => item.id)
  }
  cancelAuditAssetCardOrder(ids).then((resp) => {
    if (resp && resp.success) {
      getList()
    }
  })
}
//删除
function remove(row) {
  const data = []
  data.push(row.id)
  removeAssetCardOrder(data).then((resp) => {
    if (resp && resp.success) {
      getList()
    }
  })
}
function specialDelete(row) {
  // 特殊删除
  const data = [row.id]
  specialDeleteAssetCard(data).then((resp) => {
    if (resp && resp.success) {
      getList()
    }
  })
}
//驳回
function reject(row) {
  proxy
    .$prompt('请输入驳回理由', '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
    })
    .then(({ value }) => {
      const data = {
        id: row.id,
        checkOpt: value,
      }
      rejectAssetCardOrder(data).then((resp) => {
        if (resp && resp.success) {
          getList()
        }
      })
    })
}
//拒绝
function refuse(row) {
  proxy
    .$prompt('请输入拒绝理由', '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
    })
    .then(({ value }) => {
      const data = {
        id: row.id,
        checkOpt: value,
      }
      refuseAssetCardOrder(data).then((resp) => {
        if (resp && resp.success) {
          getList()
        }
      })
    })
}
function _assetCardSplit(row) {
  assetCardSplitDialog.value.visible = true
  assetCardSplitDialog.value.row = row
}
function financeAdjust(row) {
  getCurrentFiscalPeriod(2).then((resp) => {
    if (resp && resp.success && resp.data) {
      sessionStorage.setItem('storeRowId', row.id)
      financeModifyInfo.value.visible = true
      financeModifyInfo.value.id = row.id
      financeModifyInfo.value.currentAccountingInterval = resp.data.startDate
      financeModifyInfo.value.type = 'financeAdjust'
    } else {
      proxy.$message({
        type: 'error',
        duration: 3500,
        message: '未开启会计期间，请先开启会计期间!',
        showClose: true,
      })
    }
  })
}
//财务信息登记
function registerFinancialInformation(row) {
  getCurrentFiscalPeriod(2).then((resp) => {
    if (resp && resp.success && resp.data) {
      sessionStorage.setItem('storeRowId', row.id)
      financeModifyInfo.value.visible = true
      financeModifyInfo.value.id = row.id
      financeModifyInfo.value.currentAccountingInterval = resp.data.startDate
      financeModifyInfo.value.type = 'financeRegister'
    } else {
      proxy.$message({
        type: 'error',
        duration: 3500,
        message: '未开启会计期间，请先开启会计期间!',
        showClose: true,
      })
    }
  })
}

function updateFinancialInformation(row) {
  getCurrentFiscalPeriod(2).then((resp) => {
    if (resp && resp.success && resp.data) {
      financeModifyInfo.value.visible = true
      financeModifyInfo.value.id = row.id
      financeModifyInfo.value.currentAccountingInterval = resp.data.startDate
      financeModifyInfo.value.type = 'update'
    } else {
      proxy.$message({
        type: 'error',
        duration: 3500,
        message: '未开启会计期间，请先开启会计期间!',
        showClose: true,
      })
    }
  })
}

function returnFinanceModifyInfo() {
  if (financeModifyInfo.value.id) {
    getList()
  } else {
    search()
  }
}
//财务信息取消
function cancelFinancialInformation(row) {
  const data = []
  data.push(row.id)
  financeCancel(data).then((resp) => {
    if (resp && resp.success) {
      getList()
    }
  })
}
//财务信息确认
function confirmFinancialInformation(row = undefined) {
  let ids = []
  if (row) {
    ids.push(row.id)
  } else {
    ids = tableInfo.value.selections.map((item) => item.id)
  }
  financeRatify(ids).then((resp) => {
    if (resp && resp.success) {
      getList()
    }
  })
}
//财务信息提交
function submitFinancialInformation(row = undefined) {
  let ids = []

  if (row) {
    ids.push(row.id)
  } else {
    ids = tableInfo.value.selections.map((item) => item.id)
  }
  financeSubmit(ids).then((resp) => {
    if (resp && resp.success) {
      getList()
    }
  })
}
//财务信息驳回
function rejectFinancialInformation(row) {
  proxy
    .$prompt('请输入驳回理由', '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
    })
    .then(({ value }) => {
      const data = {
        id: row.id,
        rejectReason: value,
      }
      financeReject(data).then((resp) => {
        if (resp && resp.success) {
          getList()
        }
      })
    })
}
//财务信息撤销
function revokeFinancialInformation(row) {
  const data = []
  data.push(row.id)
  financeRevoke(data).then((resp) => {
    if (resp && resp.success) {
      getList()
    }
  })
}
// 创建
function create() {
  getCurrentFiscalPeriod(2).then((resp) => {
    if (resp && resp.success && resp.data) {
      modifyInfo.value.currentAccountingInterval = resp.data.startDate
    } else {
      proxy.$message({
        type: 'error',
        duration: 3500,
        message: '未开启会计期间，请先开启会计期间!',
        showClose: true,
      })
    }
    modifyInfo.value.type = 'create'
    modifyInfo.value.visible = true
    modifyInfo.value.title = '新增资产卡片'
    modifyInfo.value.id = null
    modifyInfo.value.canModifyModule = ''
    modifyInfo.value.buildCardData = []
  })
}
function copyCreate(row) {
  //复制并新增
  getCurrentFiscalPeriod(2).then((resp) => {
    if (resp && resp.success && resp.data) {
      modifyInfo.value.currentAccountingInterval = resp.data.startDate
    } else {
      this.$message({
        type: 'error',
        duration: 3500,
        message: '未开启会计期间，请先开启会计期间!',
        showClose: true,
      })
    }
    sessionStorage.setItem('storeRowId', row.id)
    modifyInfo.value.type = 'create'
    modifyInfo.value.id = row.id
    modifyInfo.value.visible = true
    modifyInfo.value.title = '新增资产卡片'
    modifyInfo.value.canModifyModule = ''
    modifyInfo.value.buildCardData = []
  })
}
function update(row) {
  //获取会计区间
  getCurrentFiscalPeriod(2).then((resp) => {
    if (resp && resp.success && resp.data) {
      modifyInfo.value.currentAccountingInterval = resp.data.startDate
    } else {
      proxy.$message({
        type: 'error',
        duration: 3500,
        message: '未开启会计期间，请先开启会计期间!',
        showClose: true,
      })
    }
    getBusinessKeyById({
      businessKey: row.assetCode,
      businessType: 'assetCard',
    }).then((res) => {
      if (res.success) {
        sessionStorage.setItem('storeRowId', row.id)
        if (res.data?.processInstanceId) {
          proxy.$fn.setFlowData(res.data, '', proxy.$route)
        } else {
          modifyInfo.value.type = 'update'
          modifyInfo.value.id = row.id
          modifyInfo.value.visible = true
          modifyInfo.value.title = '修改资产卡片'
          modifyInfo.value.canModifyModule = ''
          modifyInfo.value.buildCardData = []
        }
      }
    })
  })
}

function updateGroupSelections(arr) {
  filterInfo.value.query.groups = arr
  groupSelectInfo.value.selections = arr
  if (!arr.length) {
    filterInfo.value.query.groups = []
    filterInfo.value.query.groupMap = {}
    groupSelectInfo.value.data = []
    groupFlag.value = false
  }
}
function groupSelect(arr) {
  if (arr.length) {
    //点击分组
    groupFlag.value = true
    filterInfo.value.query.groups = arr
    groupSelectInfo.value.selections = arr
    getCustomizeGroupsList()
  } else {
    proxy.$message.warning({
      message: '请选择分组条件！',
      showClose: true,
      duration: 3000,
    })
  }
}

async function getCustomizeGroupsList(len, param, expande) {
  //分组查询
  let params = {}
  if (len) {
    params = param
  } else {
    params = filterInfo.value.query
  }
  if (
    filterInfo.value.query.queryDtoList &&
    filterInfo.value.query.queryDtoList.length
  ) {
    params = proxy.$fn.deepClone(params)
    params.queryMap = {}
  }
  await getAssetCardCustomizeGroups(params).then(async (res) => {
    if (res && res.success) {
      let data = res.data
      let newData = []
      if (len) {
        await data.forEach((item, index) => {
          newData.push({
            ...item,
            id: index + Math.random(),
            isColspan: true,
            children: [{ ...item, id: index + Math.random(), isColspan: true }],
          })
        })
        expande.children = newData
      } else {
        await data.forEach((item, index) => {
          newData.push({
            ...item,
            id: index + Math.random(),
            isColspan: true,
            children: [{ id: index + Math.random(), isColspan: true }],
          })
        })
        groupSelectInfo.value.data = newData
      }
    }
  })
}
function exChange(data, expandedRows) {
  //展开分组
  if (expandedRows) {
    let len = data.nextGroups.length
    if (len) {
      let params = {
        ...filterInfo.value.query,
        groups: data.nextGroups,
        groupMap: { ...data.query },
        queryMap: { ...filterInfo.value.query.queryMap, ...data.query },
      }
      getCustomizeGroupsList(len, params, data)
    } else {
      let params = {
        ...filterInfo.value.query,
        groups: [],
        groupMap: {},
        queryMap: { ...filterInfo.value.query.queryMap, ...data.query },
      }
      getAssetCardAll(params).then(async (res) => {
        if (res && res.success) {
          let resData = res.data
          await resData.forEach((item, index) => {
            item.id = index + Math.random()
            item.isColspan = false
          })
          data.children = resData
        }
      })
    }
  } else {
    data.children = [{ id: Math.random(), isColspan: true }]
  }
}

function setPreferenceCallback(obj) {
  updateUserCustomize(obj.customizeUserVO).then((res) => {
    if (res && res.success) {
      getCustomize(!slipSelectRequest.value)
    }
  })
}
function advancedSearchShow() {
  advancedSearchInfo.value.visible = true
}
async function advancedSearchCallback(obj) {
  filterInfo.value.query.queryMap = {}
  let arr = [
    {
      asTbName: 'core_asset,core_asset',
      columnName: 'use_dept_id,depot_id',
      queryType: 'IN',
      queryCategory: 'AND',
      value: 'assetSourceAuth',
    },
  ]
  filterInfo.value.query.queryDtoList = [...obj.queryDtoList, ...arr]
  advancedSearchInfo.value.data = obj.data
  if ((await groupSelectInfo.value.selections.length) > 0) {
    await getCustomizeGroupsList()
    clearType.value = !clearType.value
  } else {
    groupSelectInfo.value.data = []
    await getList()
    clearType.value = !clearType.value
  }
  filterInfo.value.query.queryMap = proxy.$fn.deepClone(
    filterInfo.value.copyQueryMap
  )
}
async function getList() {
  priceRangeFilter()
  tableInfo.value.refresh = Math.random()
  getSummary()
}
function search() {
  priceRangeFilter()
  advancedSearchInfo.value.data = {}
  filterInfo.value.query.queryDtoList = []
  if (groupSelectInfo.value.selections.length > 0) {
    getCustomizeGroupsList()
  } else {
    groupSelectInfo.value.data = []
    tableInfo.value.initCurpage = Math.random()
    tableInfo.value.refresh = Math.random()
  }
  getSummary()
}
function priceRangeFilter() {
  const priceRangeLeft =
    priceRange.value.left || priceRange.value.left == 0
      ? priceRange.value.left + ''
      : ''
  const priceRangeRight =
    priceRange.value.right || priceRange.value.right == 0
      ? priceRange.value.right + ''
      : ''
  if (priceRangeLeft && priceRangeRight) {
    filterInfo.value.query.queryMap.primitiveOriginalAmount.value =
      priceRangeLeft + ',' + priceRangeRight
  } else if (priceRangeLeft && !priceRangeRight) {
    filterInfo.value.query.queryMap.primitiveOriginalAmount.value =
      priceRangeLeft
  } else if (!priceRangeLeft && priceRangeRight) {
    filterInfo.value.query.queryMap.primitiveOriginalAmount.value =
      ',' + priceRangeRight
  } else {
    filterInfo.value.query.queryMap.primitiveOriginalAmount.value = ''
  }
}
function handleEvent(event, data) {
  switch (event) {
    case 'tableCheck':
      tableInfo.value.selections = [...data]
      break
  }
}
function clearSearch() {
  priceRange.value.left = ''
  priceRange.value.right = ''
  clearType.value = !clearType.value
  filterInfo.value.query.queryMap = proxy.$fn.deepClone(
    filterInfo.value.copyQueryMap
  )
  filterInfo.value.query.queryParams.useDeptIdMult = ''
  search()
}
function getCustomize(slipSelect = true) {
  let param = {
    tableKey: 'coreAssetCardList-com.slip.spd.entity.vo.core.CoreAssetVO',
  }
  getCustomizeSetting(param).then((res) => {
    if (res && res.success) {
      let data = res.data
      filterInfo.value.query.customizeUserVO = data
      let searchInfo = proxy.$fn.setSearchList(
        filterInfo.value.searchList,
        data.detail
      )
      let tableFieldInfo = proxy.$fn.setFieldList(
        tableInfo.value.fieldList,
        data.detail,
        true
      )

      tableInfo.value.fieldList = tableFieldInfo.fieldList
      groupSelectInfo.value.options = tableFieldInfo.groupOption
      filterInfo.value.query.queryMap = {
        ...searchInfo.queryMap,
        ...filterInfo.value.query.queryMap,
      }
      filterInfo.value.copyQueryMap = proxy.$fn.deepClone(
        filterInfo.value.query.queryMap
      )
      filterInfo.value.searchList = searchInfo.searchList
      filterInfo.value.searchList.forEach((item) => {
        item.event = search
      })
      slipSelectRequest.value = slipSelect
      tableInfo.value.api = getAssetCardCustomizePage
      getList()
    }
  })
}
function sortChange(column) {
  if (filterInfo.value.query.customizeUserVO.head.sortType === 0) {
    let arr = proxy.$fn.sortChange(column, filterInfo.value.sortArr)
    filterInfo.value.sortArr = arr
    filterInfo.value.query.sortString = arr.toString()
    getList()
  }
}
function tableRowClassName(row) {
  if (row.row.nextGroups) {
    return 'bg-color-EBEEF5'
  } else {
    return ''
  }
}
function arraySpanMethod({ row, columnIndex }) {
  if (row.nextGroups) {
    if (columnIndex === 0) {
      return {
        rowspan: 1,
        colspan: tableInfo.value.fieldList.length,
      }
    }
  }
}
function handlePrinterCallBack(printer) {
  if (printer !== false) {
    proxy.$print.buildRenderBarCode(printerInfo.value.data, printer)
  }
  printerInfo.value.visible = false
}
function downloadTemplateOpen() {
  downloadDialog.value.visible = true
}
function downloadTemplate() {
  if (downloadDialog.value.flag === 'card') {
    exportTemplateExcel('asset_card_import').then((res) => {
      if (res) {
        proxy.$fn.parseExcel(res)
      }
    })
  } else if (downloadDialog.value.flag === 'dict') {
    exportTemplateExcel('asset_card_by_dict_import').then((res) => {
      if (res) {
        proxy.$fn.parseExcel(res)
      }
    })
  } else if (downloadDialog.value.flag === 'financial_asset') {
    exportTemplateExcel('asset_financial_asset_code').then((res) => {
      if (res) {
        proxy.$fn.parseExcel(res)
      }
    })
  }
  downloadDialog.value.visible = false
}
function checkConfirm() {
  if (dialogInfo.value.type === 'excel') {
    exportExcelList()
  } else if (dialogInfo.value.type === 'print') {
    printList()
  }
  dialogInfo.value.visible = false
  dialogInfo.value.msg = ''
}
function exportExcel() {
  dialogInfo.value.visible = true
  dialogInfo.value.type = 'excel'
  dialogInfo.value.msg = '请选择数据导出范围'
  dialogInfo.value.btList[1].label = '导出'
  dialogInfo.value.flag = 'page'
}
function exportExcelList() {
  filterInfo.value.query.queryMap.id.value = ''
  if (dialogInfo.value.flag === 'select') {
    if (!tableInfo.value.selections.length) {
      proxy.$message.warning({
        message: '请选择数据！',
        showClose: true,
        duration: 3000,
      })
      return
    }
    let ids = tableInfo.value.selections.map((item) => item.id).join(',')
    filterInfo.value.query.queryMap.id.value = ids
  }
  let params = {
    ...filterInfo.value.query,
    ...page.value,
    page: dialogInfo.value.flag === 'page' ? true : false,
  }

  exportAssetCard(params).then((resp) => {
    if (resp) {
      proxy.$fn.parseExcel(resp)
    }
  })
}
async function print() {
  dialogInfo.value.visible = true
  dialogInfo.value.type = 'print'
  dialogInfo.value.msg = '请选择当数据打印范围'
  dialogInfo.value.btList[1].label = '打印'
  dialogInfo.value.flag = 'page'
}

function printList() {
  fatchTemplateByCode({
    resourceCode: 'assetCard:printListCard',
    isDefault: 1,
  }).then((res) => {
    if (res && res.success) {
      let temp = proxy.$fn.getPrintTemp(res.data[0])
      getPrintData(temp, dialogInfo.value.flag)
    }
  })
}
function getPrintData(temp, flag) {
  filterInfo.value.query.queryMap.id.value = ''
  if (dialogInfo.value.flag === 'select') {
    if (!tableInfo.value.selections.length) {
      proxy.$message.warning({
        message: '请选择数据！',
        showClose: true,
        duration: 3000,
      })
      return
    }
    let ids = tableInfo.value.selections.map((item) => item.id).join(',')
    filterInfo.value.query.queryMap.id.value = ids
  }
  let query = {
    customizeDto: filterInfo.value.query,
  }
  let params = {
    ...query,
    ...page.value,
    page: flag === 'page' ? true : false,
  }
  getAssetCardPrint(params).then((res) => {
    if (res.success && res) {
      let data = proxy.$fn.deepClone(res.data)
      let newData = data.map((item) => {
        return {
          ...item,
          ...item.orderInfo,
        }
      })
      proxy.$lodop.preview(temp, newData)
    }
  })
}
//维保信息补录
function replenishMaintenance(row) {
  //获取会计区间
  getCurrentFiscalPeriod(2).then((resp) => {
    if (resp && resp.success && resp.data) {
      modifyInfo.value.id = row.id
      modifyInfo.value.title = '信息补录'
      modifyInfo.value.type = 'update'
      modifyInfo.value.canModifyModule = 'noFinanceAsset'
      modifyInfo.value.visible = true
      modifyInfo.value.currentAccountingInterval = resp.data.startDate
    } else {
      proxy.$message({
        type: 'error',
        duration: 3500,
        message: '未开启会计期间，请先开启会计期间!',
        showClose: true,
      })
    }
  })
}
</script>

<style scoped>
.price-range {
  display: flex;
  align-items: center;
}
</style>
